import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:old_shop/login&regist/view/button_view.dart';
import 'package:old_shop/login&regist/view/normal_text.dart';

import '../common/const/cosnt.dart';

class ResetPwdPage extends StatefulWidget {
  final Map params;

  const ResetPwdPage({Key? key, required this.params}) : super(key: key);
  @override
  _ResetPwdPageState createState() => _ResetPwdPageState();
}

class _ResetPwdPageState extends State<ResetPwdPage> {
  final _pwdController = TextEditingController();
  final _pwdFocus = FocusNode();
  final _pwd2Controller = TextEditingController();
  final _pwd2Focus = FocusNode();

  @override
  void dispose() {
    _pwdController.dispose();
    _pwd2Controller.dispose();
    super.dispose();
  }

  void _submit() {
    _request();
  }

  void _request() {
    if (_pwd2Controller.text != _pwdController.text) {
      EasyLoading.showError("两次密码不一致");
      return;
    }
    EasyLoading.show(status: "Loading...");
    EasyLoading.dismiss();
    EasyLoading.showSuccess("修改成功");
    int count = 0;
    // 回到密码登录
    Navigator.popUntil(context, (route) {
      count += 1;
      return count > 2;
    });
  }

  @override
  Widget build(BuildContext context) {
    final size = MediaQuery.of(context).size;
    final marginH = size.height * 0.06;

    return Scaffold(
      backgroundColor: Colors.white,
      body: GestureDetector(
        behavior: HitTestBehavior.translucent,
        onTap: () => _pwdFocus.unfocus(),
        child: SafeArea(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              IconButton(
                icon: Icon(Icons.arrow_back_ios),
                onPressed: () => Navigator.pop(context),
              ),
              SizedBox(height: marginH),
              Padding(
                  padding: const EdgeInsets.all(20),
                  child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: <Widget>[
                    Text(
                      "找回密码",
                      style: AppFont.textStyle(25, color: AppColor.font333, fontWeight: FontWeight.bold),
                    ),
                    SizedBox(
                      height: 8,
                    ),
                    SizedBox(
                      height: marginH + 10,
                    ),
                    NormalTextfield(
                      obscureText: true,
                      maxLength: 20,
                      focusNode: _pwdFocus,
                      backgroundColor: Colors.white,
                      controller: _pwdController,
                      hintText: "请输入新密码",
                    ),
                    SizedBox(
                      height: 1,
                      child: Divider(),
                    ),
                    SizedBox(
                      height: 8,
                    ),
                    NormalTextfield(
                      obscureText: true,
                      maxLength: 20,
                      backgroundColor: Colors.white,
                      focusNode: _pwd2Focus,
                      controller: _pwd2Controller,
                      hintText: "请在次输入密码",
                    ),
                    SizedBox(
                      height: 1,
                      child: Divider(),
                    ),
                    SizedBox(height: marginH),
                    BottomButton(
                      margin: const EdgeInsets.only(top: 40),
                      title: "完成",
                      onTap: _submit,
                    ),
                  ])),
            ],
          ),
        ),
      ),
    );
  }
}
